package com.wangshb.upms.core.spring.oauth2;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.oauth2.provider.ClientDetails;
import org.springframework.security.oauth2.provider.ClientDetailsService;
import org.springframework.security.oauth2.provider.ClientRegistrationException;
import org.springframework.security.oauth2.provider.client.BaseClientDetails;

public class ClientDetailServiceImpl implements ClientDetailsService {

    @Autowired
    private UserDetailsService userDetailsService;


    @Override
    public ClientDetails loadClientByClientId(String clientId) throws ClientRegistrationException {
        UserDetails userDetails = userDetailsService.loadUserByUsername(clientId);
        BaseClientDetails baseClientDetails = new BaseClientDetails();
        baseClientDetails.setClientId(userDetails.getUsername());
        baseClientDetails.setClientSecret(userDetails.getPassword());
        baseClientDetails.setAuthorities(userDetails.getAuthorities());
        return baseClientDetails;
    }
}
